<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';

var game_deadline = '<?php echo $game_deadline ?>';

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getLotteryTimeList',
    tbar:[{
        text:'添加',
        cls:'btn-show',
        handler:function() {
            var win = new ZM.PopUp({
                title:'添加时间设置',
                defaults:{labelWidth: 120},
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/createLotteryTime',
                    success:function(res) {
                        ZM.bo.msg('success',res.detail);
                        list.grid.store.reload();
                        win.close();
                    },
                    items:[{
                        xtype:'datefield',
                        fieldLabel:'日期',
                        format:'Y-m-d',
                        name:'lottery_time_date',
                        allowBlank:false
                    },{
                        xtype:'timefield',
                        fieldLabel:'开始时间',
                        name:'lottery_time_start',
                        format:'H:i:s',
                        allowBlank:false
                    },{
                        xtype:'timefield',
                        fieldLabel:'结束时间',
                        name:'lottery_time_end',
                        format:'H:i:s',
                        allowBlank:false
                    },{
                        xtype:'numberfield',
                        fieldLabel:'汽车模型中奖概率',
                        name:'lottery_time_gift1_rate',
                        minValue:0,
                        maxValue:1,
                        allowBlank:false
                    },{
                        xtype:'intfield',
                        fieldLabel:'汽车模型数量',
                        minValue:0,
                        name:'lottery_time_gift1_count',
                        allowBlank:false
                    },{
                        xtype:'numberfield',
                        fieldLabel:'胡歌写真集中奖概率',
                        name:'lottery_time_gift2_rate',
                        minValue:0,
                        maxValue:1,
                        allowBlank:false
                    },{
                        xtype:'intfield',
                        fieldLabel:'胡歌写真集数量',
                        minValue:0,
                        name:'lottery_time_gift2_count',
                        allowBlank:false
                    },{
                        xtype:'numberfield',
                        fieldLabel:'胡歌领动cp画册中奖概率',
                        name:'lottery_time_gift3_rate',
                        minValue:0,
                        maxValue:1,
                        allowBlank:false
                    },{
                        xtype:'intfield',
                        fieldLabel:'胡歌领动cp画册数量',
                        minValue:0,
                        name:'lottery_time_gift3_count',
                        allowBlank:false
                    },{
                        xtype:'numberfield',
                        fieldLabel:'VR眼镜中奖概率',
                        name:'lottery_time_gift4_rate',
                        minValue:0,
                        maxValue:1,
                        allowBlank:false
                    },{
                        xtype:'intfield',
                        fieldLabel:'VR眼镜数量',
                        minValue:0,
                        name:'lottery_time_gift4_count',
                        allowBlank:false
                    }]
                }
            }).show();
        }
    },'-',{
        xtype:'displayfield',
        id:'deadline_time',
        value: '结束时间: '+(game_deadline ? game_deadline : '无')
    },'-',{
        text:'设置结束时间',
        cls:'btn-show',
        handler:function() {
            var win = new ZM.PopUp({
                title:'添加时间设置',
                type:'s',
                defaults:{labelWidth: 120},
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/setGameDeadline',
                    success:function(res) {
                        ZM.bo.msg('success',res.detail);
                        game_deadline = Ext.getCmp('set_game_deadline').getValue();
                        Ext.getCmp('deadline_time').setValue('结束时间: ' + game_deadline);
                        win.close();
                    },
                    items:[{
                        xtype:'datetimefield',
                        id:'set_game_deadline',
                        name:'<?php echo HD_GAME_DEADLINE ?>',
                        value:game_deadline,
                        fieldLabel:'结束时间'
                    }]
                }
            }).show();
        }
    }],
    columns:[
        {header:'ID',dataIndex:'lottery_time_id',hidden:true},
        {header:'日期',dataIndex:'lottery_time_date',sort:true,filter:{xtype:'daterangefield'}},
        {header:'开始时间',dataIndex:'lottery_time_start',sort:true},
        {header:'结束时间',dataIndex:'lottery_time_end',sort:true},
        {header:'汽车模型中奖概率',dataIndex:'lottery_time_gift1_rate',sort:true},
        {header:'汽车模型数量',width:120,dataIndex:'lottery_time_gift1_count',sort:true},
        {header:'汽车模型剩余数量',width:120,dataIndex:'lottery_time_gift1_count_drawn',renderer:function(val,m,r) {
            return r.json.lottery_time_gift1_count - val;
        }},
        {header:'胡歌写真集中奖概率',dataIndex:'lottery_time_gift2_rate',sort:true},
        {header:'胡歌写真集数量',width:120,dataIndex:'lottery_time_gift2_count',sort:true},
        {header:'胡歌写真集剩余数量',width:120,dataIndex:'lottery_time_gift2_count_drawn',renderer:function(val,m,r) {
            return r.json.lottery_time_gift2_count - val;
        }},
        {header:'胡歌领动cp画册中奖概率',dataIndex:'lottery_time_gift3_rate',sort:true},
        {header:'胡歌领动cp画册数量',width:120,dataIndex:'lottery_time_gift3_count',sort:true},
        {header:'胡歌领动cp画册剩余数量',width:120,dataIndex:'lottery_time_gift3_count_drawn',renderer:function(val,m,r) {
            return r.json.lottery_time_gift3_count - val;
        }},
        {header:'VR眼镜中奖概率',dataIndex:'lottery_time_gift4_rate',sort:true},
        {header:'VR眼镜数量',width:120,dataIndex:'lottery_time_gift4_count',sort:true},
        {header:'VR眼镜剩余数量',width:120,dataIndex:'lottery_time_gift4_count_drawn',renderer:function(val,m,r) {
            return r.json.lottery_time_gift4_count - val;
        }},
        {header:'创建时间',dataIndex:'lottery_time_time_create',width:140},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            str += Ext.rd('编辑','fireEdit',r,attr.ctrlName+'/editLotteryTime');
            str += Ext.rd('删除','fireDelete',r,attr.ctrlName+'/deleteLotteryTime','red');
            return str;
        }}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireEdit = function(r) {
    var r = r.json;
    var win = new ZM.PopUp({
        title:'添加时间设置',
        defaults:{labelWidth: 120},
        items:{
            xtype:'formpanel',
            url:list.baseUrl+ attr.ctrlName+'/editLotteryTime',
            success:function(res) {
                ZM.bo.msg('success',res.detail);
                list.grid.store.reload();
                win.close();
            },
            params:{lottery_time_id:r.lottery_time_id},
            items:[{
                xtype:'datefield',
                fieldLabel:'日期',
                format:'Y-m-d',
                value:r.lottery_time_date,
                name:'lottery_time_date',
                allowBlank:false
            },{
                xtype:'timefield',
                fieldLabel:'开始时间',
                name:'lottery_time_start',
                value:r.lottery_time_start,
                format:'H:i:s',
                allowBlank:false
            },{
                xtype:'timefield',
                fieldLabel:'结束时间',
                name:'lottery_time_end',
                value:r.lottery_time_end,
                format:'H:i:s',
                allowBlank:false
            },{
                xtype:'numberfield',
                fieldLabel:'汽车模型中奖概率',
                name:'lottery_time_gift1_rate',
                value:r.lottery_time_gift1_rate,
                minValue:0,
                maxValue:1,
                allowBlank:false
            },{
                xtype:'intfield',
                fieldLabel:'汽车模型数量',
                minValue:0,
                name:'lottery_time_gift1_count',
                value:r.lottery_time_gift1_count,
                allowBlank:false
            },{
                xtype:'numberfield',
                fieldLabel:'胡歌写真集中奖概率',
                name:'lottery_time_gift2_rate',
                value:r.lottery_time_gift2_rate,
                minValue:0,
                maxValue:1,
                allowBlank:false
            },{
                xtype:'intfield',
                fieldLabel:'胡歌写真集数量',
                minValue:0,
                name:'lottery_time_gift2_count',
                value:r.lottery_time_gift2_count,
                allowBlank:false
            },{
                xtype:'numberfield',
                fieldLabel:'胡歌领动cp画册中奖概率',
                name:'lottery_time_gift3_rate',
                value:r.lottery_time_gift3_rate,
                minValue:0,
                maxValue:1,
                allowBlank:false
            },{
                xtype:'intfield',
                fieldLabel:'胡歌领动cp画册数量',
                minValue:0,
                name:'lottery_time_gift3_count',
                value:r.lottery_time_gift3_count,
                allowBlank:false
            },{
                xtype:'numberfield',
                fieldLabel:'VR眼镜中奖概率',
                name:'lottery_time_gift4_rate',
                value:r.lottery_time_gift4_rate,
                minValue:0,
                maxValue:1,
                allowBlank:false
            },{
                xtype:'intfield',
                fieldLabel:'VR眼镜数量',
                minValue:0,
                name:'lottery_time_gift4_count',
                value:r.lottery_time_gift4_count,
                allowBlank:false
            }]
        }
    }).show();
}

list.grid.fireDelete = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确定?','确定要删除时间段['+r.lottery_time_date+'('+r.lottery_time_start+'~'+r.lottery_time_end+')]?',function(btn) {
        if(btn == 'yes') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/deleteLotteryTime',
                params:{lottery_time_id:r.lottery_time_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}


<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>